import type { ConsultType } from '@/enums'
import type { ConsultIllness, PartialConsult } from '@/types/consult'
import { defineStore } from 'pinia'
import { ref } from 'vue'

export const useConsultStore = defineStore(
  'cp-consult',
  () => {
    // 所有收集到的数据，【数据必须 return】
    const consult = ref<PartialConsult>({})

    // !#1 设置问诊的类型
    const setType = (type: ConsultType) => {
      consult.value.type = type
    }
    // !#2 设置急速问诊的类型，0 普通 1 三甲
    const setIllnessType = (illnessType: 0 | 1) => {
      consult.value.illnessType = illnessType
    }
    // !#3 设置科室
    const setDep = (id: string) => {
      consult.value.depId = id
    }

    // !#4 病情描述
    const setIllness = (illness: ConsultIllness) => {
      // 病情描述
      consult.value.illnessDesc = illness.illnessDesc
      // 患病时间
      consult.value.illnessTime = illness.illnessTime
      // 是否就诊过
      consult.value.consultFlag = illness.consultFlag
      // 图片数组
      consult.value.pictures = illness.pictures
    }

    // !#5 设置患者 ID
    const setPatient = (id: string) => (consult.value.patientId = id)
    // !#6 设置优惠券
    const setCoupon = (id?: string) => (consult.value.couponId = id)
    // !#7 清空记录
    const clear = () => (consult.value = {})

    return {
      consult,
      setType,
      setIllnessType,
      setDep,
      setIllness,
      setPatient,
      setCoupon,
      clear
    }
  },
  {
    persist: true
  }
)
